import { ChangeDetectionStrategy, ChangeDetectorRef, Component, DoCheck, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';

@Component({
  selector: 'app-items',
  templateUrl: './items.component.html',
  styleUrls: ['./items.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class ItemsComponent implements OnInit, OnChanges, DoCheck {
  private _item:any;
  @Input() 
  get item() {
    return this._item;
  }
  set item(val) {
    console.log(val)
    this._item = val;
  }
  constructor(
    private changeDetectorRef: ChangeDetectorRef
  ) { }

  ngOnInit(): void {
  }

  ngOnChanges(changes: SimpleChanges) {
    console.log(changes);
  }

  click() {
    console.log('click'); // 事件触发会导致变更检测
  }
  
  ngDoCheck() {
    console.log('docheck', this.item);
    this.changeDetectorRef.markForCheck();
  }
  
}
